<%@page import="shop.vo.ProTypeBean"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="shop.factory.DAOFactory"%>
<%@page import="shop.vo.ProductBean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/bootstrap.min.css">
<script src="../js/jquery-1.10.2.min.js" type="text/javascript"
	charset="utf-8"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<title>商品信息查看</title>
</head>
<body>
<%
	if (!(boolean)session.getAttribute("adminLogin")) {
		String path = request.getContextPath() + "/Admin/login.jsp";
		response.sendRedirect(path);
	}
%>
<body>
	<div class="container-fluid">
		<h3>商品信息查看</h3>
		<div class="page-header" style="margin-top:10px;"></div>
		<form action="<%=request.getContextPath() %>/ProductServlet" method="post">
		<input type="hidden" name="action" value="delete">
		<table class="table table-bordered table-condensed table-striped">
				<tr>
					<th>多选</th>
					<th>序号</th>
					<th>商品名称</th>
					<th>商品简介</th>
					<th>价格</th>
					<th>库存量</th>
					<th>质量保证说明</th>
					<th>大图路径</th>
					<th>小图路径</th>
					<th>类别</th>
					<th>操作</th>
				</tr>
				
				<%	
					int nowPage = 1;
					int pageSize = 10;
					String str = request.getParameter("to");
					if (str != null) {
						nowPage = Integer.parseInt(str);
					}
					int up = nowPage;
					int next = nowPage;
					int maxPage = 0;
					int count = DAOFactory.getIProductDAOInstance().getCount();
					if (count % pageSize == 0) {
						maxPage = count / pageSize;
					} else {
						maxPage = (count / pageSize) + 1;
					}
					if (next < maxPage) {
						next += 1;
					}
					if (up > 1) {
						up -= 1;
					}
					List<ProductBean> list = DAOFactory. getIProductDAOInstance().list(
							nowPage, pageSize);
					Iterator<ProductBean> it = list.iterator();
					while (it.hasNext()) {
						//UserBean user = it.next();
						ProductBean product = it.next();
						ProTypeBean ptype = product.getPtype();
				%>
				<tr>
					<td><input type="checkbox"
						value="<%=product.getPro_id()%>" id="cheboxId" name="cheboxId"></td>
					<td><%=product.getPro_id()%></td>
					<td><%=product.getPro_name()%></td>
					<td><%=product.getPro_description()%></td>
					<td><%=product.getPrice()%></td>
					<td><%=product.getNum()%></td>
					<td><%=product.getPro_param()%></td>
					<td><%=product.getPro_img()%></td>
					<td><%=product.getPro_litlleimg()%></td>
					<td><%=ptype.getPtype_name()%></td>
					<td><a href="">修改</a></td>
				</tr>
				<%
					}
				%>
				
				<tr>
					<td align="center" colspan="12"><input type="button"
						value="全选" onclick="quan()">&nbsp;&nbsp;&nbsp;&nbsp;<input
						type="button" value="反选" onclick="fan()">&nbsp;&nbsp;&nbsp;&nbsp;<input
						type="reset" value="重置">&nbsp;&nbsp;&nbsp;&nbsp;<input
						type="submit" value="删除" onclick="return confirm('是否删除？')"></td>
				</tr>
				<tr>
					<td colspan="12" align="center"><span class="style1"> <a
							href="productList.jsp?to=1">首页</a>&nbsp;|&nbsp; <a
							href="productList.jsp?to=<%=up%>">上一页</a>&nbsp;|&nbsp;<a
							href="productList.jsp?to=<%=next%>">下一页</a>&nbsp;|&nbsp; <a
							href="productList.jsp?to=<%=maxPage%>">尾页</a>
					</span> &nbsp;&nbsp;第&nbsp;<%=nowPage%>&nbsp;页/共&nbsp;<%=maxPage%>&nbsp;页</td>
				</tr>
			</table>
		</form>
	</div>
</body>
<script type="text/javascript">
	function quan() {
		var checkObj = document.all("cheboxId");
		for (var i = 0; i < checkObj.length; i++) {
			checkObj[i].checked = true;
		}
	}
	function fan() {
		var checkObj = document.all("cheboxId");
		for (var i = 0; i < checkObj.length; i++) {
			if (checkObj[i].checked == true)
				checkObj[i].checked = false;
			else
				checkObj[i].checked = true;
		}
	}
</script>
</html>